Use case: SMBUS slave receive in interrupt mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define SMBUS_ADDRESS 0x42
/* Buffer used for SMBUS transmission */
uint8_t aTxBuffer[] = " ****SMBUS_TwoBoards communication using autonomous mode functionality**** ";
/* Buffer used for SMBUS reception */
uint8_t aRxBuffer[RXBUFFERSIZE];
/* Size of SMBUS Transmission buffer */
#define RXBUFFERSIZE (COUNTOF(aTxBuffer) - 1)
void main()
{
// Add your Init and config code
/* Enable address Match detect with interrupt */
HAL_SMBUS_EnableListen_IT(&hsmbus2);
/* Wait until address matched */
/* Put SMBUS peripheral in reception process */
HAL_SMBUS_Slave_Receive_IT(&hsmbus2, (uint8_t *)aRxBuffer, RXBUFFERSIZE, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC);
/*wait end of SMBUS tranfert*/
/* Compare the sent and received buffers */
while (1)
{
}
}
/* Slave address match callbacks */
void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus,uint8_t TransferDirection, uint16_t AddrMatchCode)
{
/* Get the slave address match code */
}
/* SMBUS error callback */
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *SMBUSHandle)
{
if (HAL_SMBUS_GetError(SMBUSHandle) != HAL_SMBUS_ERROR_ACKF)
{
/* Handle the error here */
}
}
/* SMBUS event interrupt handler */
void I2C2_EV_IRQHandler(void)
{
HAL_SMBUS_EV_IRQHandler(&hsmbus2);
}
/* SMBUS error interrupt handler */
void I2C2_ER_IRQHandler(void)
{
HAL_SMBUS_ER_IRQHandler(&hsmbus2);
}
|
#define SMBUS_ADDRESS 0x42
/* Buffer used for SMBUS transmission */
uint8_t aTxBuffer[] = " ****SMBUS_TwoBoards communication using autonomous mode functionality**** ";
/* Buffer used for SMBUS reception */
uint8_t aRxBuffer[RXBUFFERSIZE];
/* Size of SMBUS Transmission buffer */
#define RXBUFFERSIZE (COUNTOF(aTxBuffer) - 1)
void main()
{
hal_smbus_handle_t hsmbus2;
// Add your Init and config code
/* Enable address Match detect with interrupt */
HAL_SMBUS_SLAVE_EnableListen_IT(&hsmbus2);
/* Put SMBUS peripheral in reception process */
HAL_SMBUS_SLAVE_SEQ_Receive_IT(&hsmbus2, (uint8_t *)aRxBuffer, RXBUFFERSIZE, HAL_SMBUS_XFER_FIRST_AND_LAST_FRAME_NO_PEC);
/*wait end of SMBUS tranfert*/
while (hsmbus2.global_state != HAL_SMBUS_STATE_IDLE);
/* Compare the sent and received buffers */
while (1)
{
}
}
/* SMBUS event interrupt handler */
void I2C2_EV_IRQHandler(void)
{
HAL_SMBUS_EV_IRQHandler(&hsmbus2);
}
/* SMBUS error interrupt handler */
void I2C2_ER_IRQHandler(void)
{
HAL_SMBUS_ER_IRQHandler(&hsmbus2);
}
/* Slave address match callbacks */
void HAL_SMBUS_AddrCallback(SMBUS_HandleTypeDef *hsmbus,uint8_t TransferDirection, uint16_t AddrMatchCode)
{
/* Get the slave address match code */
}
/* SMBUS error callback */
void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *SMBUSHandle)
{
if (HAL_SMBUS_GetError(SMBUSHandle) != HAL_SMBUS_ERROR_ACKF)
{
/* Handle the error here */
}
}
|
Key changes ¶
Listen enable API changes from
HAL_SMBUS_EnableListen_IT()toHAL_SMBUS_SLAVE_EnableListen_IT().Slave receive API changes from
HAL_SMBUS_Slave_Receive_IT()toHAL_SMBUS_SLAVE_SEQ_Receive_IT().Transfer options use the
HAL_SMBUS_XFER_*naming scheme in HAL2.The buffer size parameter is expressed in bytes in HAL2 (
Size_byte) instead of the number of data elements in HAL1 (Size).
![@startuml
title : <font size:28>SMBUS slave receive interruption mode
participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL SMBUS</b></font>" as SMBUS
participant "System HW interruption" as interruption
group#Linen SMBUS operation
appli->SMBUS : <font color=green><b>HAL_SMBUS_Slave_Receive_IT()
return
SMBUS->SMBUS : Enable SMBUS selected interruptions
interruption <[#red]-x? : <font color=red><b>SMBUS IRQ event
interruption <[#red]-x? : <font color=red><b>SMBUS IRQ error
interruption -> appli_IRQ : I2Cx_EV_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> SMBUS : HAL_SMBUS_EV_IRQHandler()
interruption -> appli_IRQ : I2Cx_ER_IRQHandler()
appli_IRQ -> SMBUS : HAL_SMBUS_ER_IRQHandler()
return
deactivate appli_IRQ
SMBUS -> appli_IRQ: <font color=green><b>HAL_SMBUS_AddrCallback()
return
SMBUS -> appli_IRQ: <font color=green><b>HAL_SMBUS_ErrorCallback()
return
SMBUS -> appli_IRQ: <font color=green><b>HAL_SMBUS_GetError()
return
@enduml](../../../../../_images/plantuml-0c7abab51e5eb65a2e83787fc762bf641010d1ee.png)
![@startuml
title : <font size:28>SMBUS slave receive interruption mode
participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL SMBUS</b></font>" as SMBUS
participant "System HW interruption" as interruption
group#Linen SMBUS operation
appli->SMBUS : <font color=green><b>HAL_SMBUS_SLAVE_SEQ_Receive_IT()
return
SMBUS->SMBUS : Enable SMBUS selected interruptions
interruption <[#red]-x? : <font color=red><b>SMBUS IRQ event
interruption <[#red]-x? : <font color=red><b>SMBUS IRQ error
interruption -> appli_IRQ : I2Cx_EV_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> SMBUS : HAL_SMBUS_EV_IRQHandler()
interruption -> appli_IRQ : I2Cx_ER_IRQHandler()
appli_IRQ -> SMBUS : HAL_SMBUS_ER_IRQHandler()
return
deactivate appli_IRQ
SMBUS -> appli_IRQ: <font color=green><b>HAL_SMBUS_ErrorCallback()
return
SMBUS -> appli_IRQ: <font color=green><b>HAL_SMBUS_GetLastErrorCodes()
return
@enduml](../../../../../_images/plantuml-0cbf4d6aac49649d965d5cb5ddf7df321815a2e7.png)